package java05;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface IntegerStack{
	public Integer push(Integer item);
	public Integer pop();
	public Integer peek();
	public boolean empty();
	public int size();
}
class ArrayListIntegerStack implements IntegerStack{
	private List<Integer> list;
	public ArrayListIntegerStack(){
		list = new ArrayList<Integer>();
	}
	public Integer push(Integer item){
		if(item==null)
			return null;
		list.add(item);
		return item;
		
	}
	public Integer pop(){
		if(list.isEmpty())
			return null;
		Integer a= list.get(list.size()-1);
		list.remove(list.get(list.size()-1));
		return a;
	}
	public Integer peek(){
		if(list.isEmpty())
			return null;
		return list.get(list.size()-1);
	}
	public boolean empty(){
		return list.isEmpty();
	}
	public int size(){
		return list.size();
	}
	public String toString() {
		return list.toString();
	}
}

public class Java51 {

	public static void main(String[] args) {
		ArrayListIntegerStack arr = new ArrayListIntegerStack();
		Scanner in = new Scanner(System.in);
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			Integer b = in.nextInt();
			System.out.println(arr.push(b));
		}
		System.out.println(arr.peek()+","+ arr.empty()+","+arr.size());
		System.out.println(arr.toString());
		int n = in.nextInt();
		for (int i = 0; i < n; i++) {
			System.out.println(arr.pop());
		}
		System.out.println(arr.peek()+","+ arr.empty()+","+arr.size());
		System.out.println(arr.toString());
	}
}